<template>
	<view class="wp">
		<view class="list" v-if="addressList.length>0">
			<view class="item" v-for="(item,index) in addressList" @click="back(item)">
				<view class="info">
					<view class="tit">{{item.realname}}</view>
					<view class="mobile">{{item.mobile}}</view>
				</view>
				<view class="edit" @click="add(index)">编辑</view>
			</view>
		</view>
		<view class="totalBtn" @click="add()">添加提货人</view>
		<uni-popup ref="popup" background-color="#fff" type="bottom">
			<view class="popup-content">
				<view class="p_line">
					<label for="">提货人</label>
					<input type="text" v-model="info.realname" placeholder="请输入姓名">
				</view>
				<view class="p_line">
					<label for="">手机号</label>
					<input type="number" v-model="info.mobile" placeholder="请输入手机号">
				</view>
				<view class="p_btn" @click="save">保存</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				optionid: '',
				total: '',
				zhiboid: '',
				options: '',
				addressList: [],
				page: 0,
				info: {
					id: '',
					realname: '',
					mobile: ''
				}
			};
		},
		
		onLoad(option) {
			this.zhiboid = option.zhiboid;
			this.zhiboid = this.zhiboid == undefined ? '' : this.zhiboid;
			if (option.source) {
				this.source = option.source;
			}
			this.options = option;
		},
		onShow() {
			let that = this;
			that.type = that.options.type;
			that.id = that.options.id;
			that.optionid = that.options.optionid;
			that.total = that.options.total;
			that.isVip = that.options.isVip;
			that.getList();
		},
		methods: {
			back(item){
				uni.setStorageSync('addre', JSON.stringify(item));
				uni.navigateTo({
					url: '/pages/order/createOrder?type=' + this.type + '&id=' + this.id + '&optionid=' + this.optionid + '&total=' +
						this.total + '&source=2&zhiboid=' + this.zhiboid+'&isVip='+this.isVip
				})
			},
			add(index){
				this.$refs.popup.open()
				if(index>=0){
					this.info = JSON.parse(JSON.stringify(this.addressList[index]));
				}
			},
			save(){
				if(this.info.realname=='') return this.$api.msg('请输入姓名');
				if(this.info.mobile=='') return this.$api.msg('请输入手机号');
				this.$axios('paymarket/addAddress', "POST", 'order',this.info).then(res => {
					if (res.data.code == 200) {
						this.$api.msg(res.data.data);
						this.info.realname = '';
						this.info.mobile = '';
						this.$refs.popup.close();
						this.getList();
					}
				})
			},
			getList(){
				this.$axios('paymarket/getAddress', "POST", 'order').then(res => {
					if (res.data.code == 200) {
						this.addressList = res.data.data.list;
					}
				})
			}
		}
	}
</script>

<style lang="scss">
page{
	background: #f8f8fe;
	padding-bottom: 40rpx;
}
.wp{
	padding: 20rpx;
}
.list{
	.item{
		display: flex;
		justify-content: space-between;
		align-items: center;
		background: #fff;
		border-radius: 12rpx;
		padding: 30rpx;
		margin-bottom: 20rpx;
		.tit{
			font-weight: bold;
			margin-bottom: 20rpx;
		}
		.mobile{
			font-size: 24rpx;
		}
		.edit{
			color: #666;
		}
		
	}
}
.popup-content{
	padding: 60rpx 30rpx;
	text-align: center;
	.p_line{
		margin-bottom: 40rpx;
		label{
			font-weight: bold;
			margin-bottom: 20rpx;
			font-size: 32rpx;
		}
		input{
			border-bottom: 1rpx solid #eee;
			margin: 20rpx auto;
			font-size: 30rpx;
			height: 60rpx;
		}
	}
	.p_btn{
		width: 396rpx;
		height: 74rpx;
		background: linear-gradient( 270deg, #8917E2 0%, #B92DF1 100%);
		border-radius: 38rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 74rpx;
		margin: 80rpx auto 20rpx;
	}
}
</style>
